package model;

import java.util.ArrayList;
import java.util.List;
import resources.ResourceManager;

import model.CommandNode;

/**
 * @author Kevin
 *
 * TODO: figure out how I want to incorporate the resources and such.
 * 
 * Summary of complexity:
 * Each command has multiple string token representations.
 * 
 * Different commands have different numbers of arguments
 * 
 * Different commands have different 
 * 
 *
 */
public class Parser {

	private static final String PARSING_FILE_NAME = "parsingdata";
	private static final String PARSING_KEYS = "tokens";
	
	List<ParsingData> parsingData = new ArrayList<ParsingData>();
	
	public Parser(){
		
		ResourceManager rm = new ResourceManager(PARSING_FILE_NAME);
				
		String[] operatorKeys = rm.getStringArray(PARSING_KEYS);
				
		ArrayList<ParsingData> parsingDataList = new ArrayList<ParsingData>();
		
        for(String key : operatorKeys)
        {
            String symbol = rm.getString(key+".symbol");
            int priority = rm.getInteger(key+".priority");
            int numArgs = rm.getInteger(key+".args");
            boolean isFunction = rm.getBoolean(key+".function");
            boolean isLeftAssoc = rm.getBoolean(key+".leftAssoc");
            String tokenClass = rm.getString(key+".token");
            String exprClass = rm.getString(key+".expr");
            
			ParsingData op;
			try {
				op = new ParsingData(symbol, priority, numArgs,
				                                 isFunction, isLeftAssoc,
				                                 tokenClass, exprClass);
				parsingDataList.add(op);
			} catch (ClassNotFoundException e) {
				e.printStackTrace();
			}
		}
        parsingData = parsingDataList;
		
	}
	
	//TODO: make this a more advanced tokenizer in the future
	public String[] tokenize(String s){
		String[] tokens;
		tokens = s.split(" ");
		return tokens;
	}
	//Takes a string line and splits it into string array of tokens.
	
	
	public List<CommandNode> assembleTree(List<String[]> list){
		
		//TODO: complete the tree assembler
		
		
		
		return new ArrayList<CommandNode>();
	}
	//Takes a list of tokens and fashions a list of head-CommandNodes
	
	private String regexMatch(String token){
		
		
		
		return "";
	}
	
	
}